#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

# Run a simple backup of the Bacula build directory while
#   Maximum Volume Jobs = 1 and with Maximum File Size small.
#   Ensure that only one Max Volume Jobs=1 INFO message
#   is printed.  A bug caused it to be printed multiple
#   times.
#
TestName="max-vol-jobs-test"
JobName=Incremental 
. scripts/functions

${rscripts}/cleanup
${rscripts}/copy-test-confs
echo "${tmpsrc}" >${tmp}/file-list
mkdir -p ${tmpsrc}
cp -p ${src}/src/dird/*.* ${tmpsrc}
cp -p ${src}/src/stored/*.* ${tmpsrc}
cd ${cwd}

$bperl -e 'add_attribute("$conf/bacula-dir.conf", "Maximum Volume Jobs", "1", "Pool")'
$bperl -e 'add_attribute("$conf/bacula-sd.conf", "Maximum File Size", "100000", "Device")'

change_jobname CompressedTest $JobName
start_test

cat <<END_OF_DATA >${tmp}/bconcmds
@output /dev/null
messages
@$out ${tmp}/log1.out
setdebug level=0 dir
@#setdebug level=200 storage=File
setdebug level=0 client
label storage=File volume=TestVolume001
label storage=File volume=TestVolume002
label storage=File volume=TestVolume003
label storage=File volume=TestVolume004
run job=$JobName level=Full yes
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File
stop_bacula

num=`grep -c "Max Volume jobs=1" ${tmp}/log1.out`
if [ $num != 1 ] ; then
  print_debug "ERROR: Should have only 1 Max Volume jobs=1 ..., but found $num"
  estat=1
fi
end_test
